function [R2_se,R2_fractile,beta_se,beta_fractile] = getR2SEboot(Y,X,window,numBoot)

data   = [Y X];
bsdata = block_bootstrap(data,window,numBoot);
Yboot  = squeeze(bsdata(:,1,:));
Xboot  = squeeze(bsdata(:,2:end,:));
R2boot = zeros(1,numBoot);
betaBoot = zeros(size(X,2),numBoot);
for b=1:numBoot
    %results=nwest(Yboot(:,b),Xboot(:,:,b),0);
    %R2boot(1,b) = results.rsqr;
    %betaBoot(:,b) = results.beta;
    beta = (Xboot(:,:,b)'*Xboot(:,:,b))\(Xboot(:,:,b)'*Yboot(:,b));
    resid = Yboot(:,b)-Xboot(:,:,b)*beta;
    ym    = Yboot(:,b) - mean(Yboot(:,b));
    R2boot(1,b) = 1-(resid'*resid)/(ym'*ym);
    betaBoot(:,b) = beta;
end
R2_se = std(R2boot);
R2_fractile = prctile(R2boot,[2.5 97.5]);
beta_se = std(betaBoot,0,2);
beta_fractile = prctile(betaBoot,[2.5 97.5],2);